package com.mfh.auto.create.mvvm.autocreatemvvm.file.v2

import com.intellij.psi.PsiDirectory
import com.mfh.auto.create.mvvm.autocreatemvvm.Config
import com.mfh.auto.create.mvvm.autocreatemvvm.file.BaseFileModel
import com.mfh.auto.create.mvvm.autocreatemvvm.utils.CreateFileUtils

object ViewHolderFileModelV2 : BaseFileModel() {

    override fun buildFileName() = "${Config.name}ViewHolder.kt"

    override fun buildContentString(directory: PsiDirectory): String {
        val name = Config.name
        val bindingName = "Item${name}Binding"
        val projectPackage = getProjectPackage(directory)
        return buildString {
            appendLine("package ${CreateFileUtils.getPackageByDirectory(directory)}")
            appendLine()
            appendLine("import android.view.View")
            appendLine("import ${Config.libPackageNameV2}.annotation.ItemType")
            appendLine("import ${Config.libPackageNameV2}.base.BaseViewHolder")
            appendLine("import ${Config.libPackageNameV2}.bean.FileBean")
            appendLine("import ${Config.libPackageNameV2}.interfaces.ITypeBean")
            if (projectPackage.isNotEmpty()) {
                appendLine("import ${projectPackage}.databinding.$bindingName")
            }
            appendLine()
            appendLine("/**")
            appendLine(" * @desc: ${Config.desc}")
            appendLine(" */")
            appendLine("@ItemType(ITypeBean.ITEM_TYPE_COMMON)")
            appendLine("class ${name}ViewHolder(view: View) : BaseViewHolder<FileBean, ${bindingName}>(view) {")
            appendLine()
            appendLine("    override fun onBindViewHolder(item: Any?) {")
            appendLine("        binding.bean = getItemBean(item)")
            appendLine()
            appendLine("    }")
            appendLine()
            appendLine("}")
        }
    }

}